package com.jt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class Test2Application {
    public static void main(String[] args) {
        SpringApplication.run(Test2Application.class,args);
    }
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
     return new RestTemplate(); }
     @RestController
     public class Test2{
        @Autowired
        private RestTemplate restTemplate;
        @Value("${server.port:8080}")
        private String server;
        @Autowired
        private LoadBalancerClient loadBalancerClient;
         //localhost:8091/user/test2
        @GetMapping("/user/test")
         public String get(){
            String url=String.format("http://%s/user/acho/%s","test1",server);
            return restTemplate.getForObject(url,String.class);
        }



    }



}
